<script lang="ts" setup>
import { ref } from 'vue'
import baseDialog from '@/components/baseDialog.vue';

const dialog = ref()
const submit = () => {
  if (typeDialog.value == "新增用户") {
    console.log('新增逻辑');
  } else {
    console.log('编辑逻辑');
  }
  dialog.value.dialogVisible = false
}

const row = ref({
  username: '张三',
  password: '123456',
  email: '1234@qq.com',
  phone: '19982050503',
  role: 'user',
})

const typeDialog = ref('')
const form = ref({
  username: '',
  password: '',
  email: '',
  phone: '',
  role: '',
})
const add = () => {
  form.value = {
    username: '',
    password: '',
    email: '',
    phone: '',
    role: '',
  }
  typeDialog.value = '新增用户'
  dialog.value.openDialog()
}
const edit = () => {
  typeDialog.value = '编辑用户'
  form.value = row.value
  dialog.value.openDialog()
}
</script>

<template>
  <el-button type="primary" @click="add">新增</el-button>
  <el-button type="primary" @click="edit">编辑</el-button>


  <!-- 弹框 -->
  <baseDialog ref="dialog" @comfirm="submit" :title="typeDialog">
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="用户名">
        <el-input v-model="form.username" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email" />
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="form.phone" />
      </el-form-item>
    </el-form>
  </baseDialog>
</template>

<style scoped lang="scss"></style>